home *** CD-ROM | disk | FTP | other *** search
/ Gigantic Games 2 / Gigantic Games 2.iso / pc / _z_ / zorkmachine / console.c < prev    next >
C/C++ Source or Header  |  1994-12-23  |  44KB  |  1,959 lines

  1. #include <intuition/intuitionbase.h>
  2. #include <libraries/translator.h>
  3. #include <workbench/workbench.h>
  4. #include <libraries/gadtools.h>
  5. #include <workbench/startup.h>
  6. #include <graphics/gfxbase.h>
  7. #include <devices/narrator.h>
  8. #include <devices/conunit.h>
  9. #include <libraries/asl.h>
  10. #include <dos/dostags.h>
  11. #include <exec/memory.h>
  12.  
  13. #include <clib/intuition_protos.h>
  14. #include <clib/gadtools_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/icon_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/asl_protos.h>
  19. #include <clib/wb_protos.h>
  20.  
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <stdarg.h>
  24.  
  25. #include "Zorkmachine.h"
  26.  
  27. enum    {    MEN_DUMMY,
  28.         MEN_SAVE, MEN_SAVEAS, MEN_RESTORE, MEN_SCRIPT, MEN_PALETTE, MEN_ABOUT, MEN_QUIT,
  29.         MEN_LOOK, MEN_WAIT, MEN_INVENTORY, MEN_DIAGNOSE,
  30.         MEN_RESTART, MEN_VERBOSE, MEN_BRIEF, MEN_SUPERBRIEF, MEN_SCORE, MEN_TIME, MEN_SPEECH,
  31.         MEN_NORTH, MEN_EAST, MEN_SOUTH, MEN_WEST, MEN_NORTHEAST, MEN_SOUTHEAST, MEN_SOUTHWEST, MEN_NORTHWEST, MEN_UP, MEN_DOWN, MEN_IN, MEN_OUT,
  32.         MEN_VERIFY, MEN_VERSION, MEN_DEBUG };
  33.  
  34. enum    {    GAD_STRING, GAD_WIDTH, GAD_ACCEPT, GAD_SELECT, GAD_CANCEL };
  35. enum    {    GAD_PALETTE_COLOURS, GAD_PALETTE_RED, GAD_PALETTE_GREEN, GAD_PALETTE_BLUE, GAD_PALETTE_USE, GAD_PALETTE_CANCEL };
  36.  
  37. #define SIG_CONSOLE    (1 << ConReadPort -> mp_SigBit)
  38. #define SIG_WINDOW    (1 << Window -> UserPort -> mp_SigBit)
  39. #define SIG_DEBUG    (DebugWindow ? (1 << DebugWindow -> UserPort -> mp_SigBit) : NULL)
  40. #define SIG_WORKBENCH    (WorkbenchPort ? (1 << WorkbenchPort -> mp_SigBit) : NULL)
  41. #define SIG_SPEECH    (1 << NarratorPort -> mp_SigBit)
  42. #define SIG_TEXT    (1 << SpeechPort -> mp_SigBit)
  43. #define SIG_KILL    SIGBREAKF_CTRL_C
  44. #define SIG_HANDSHAKE    SIGBREAKF_CTRL_D
  45. #define SIG_STOP    SIGBREAKF_CTRL_E
  46.  
  47. #define GT_STRING(G)    (((struct StringInfo *)(((struct Gadget *)(G)) -> SpecialInfo)) -> Buffer)
  48. #define GT_INTEGER(G)    (((struct StringInfo *)(((struct Gadget *)(G)) -> SpecialInfo)) -> LongInt)
  49.  
  50. #ifdef LATTICE
  51.  
  52. ULONG CXBRK(VOID) { return(NULL); }
  53.  
  54. #endif
  55.  
  56. #ifdef AZTEC_C
  57.  
  58. LONG Chk_Abort(VOID) { return(NULL); }
  59.  
  60. VOID _wb_parse() {}
  61.  
  62. #define __chip
  63. #define __saveds
  64.  
  65. #endif
  66.  
  67. VOID                SayMore(UBYTE *a,UBYTE *b);
  68. VOID __saveds            SpeechServer(VOID);
  69. VOID                DeleteSpeech(VOID);
  70. BYTE                CreateSpeech(VOID);
  71. VOID                BlockWindow(VOID);
  72. VOID                UnblockWindow(VOID);
  73. BOOL                ShowRequest(UBYTE *Text,UBYTE *Gadgets,...);
  74. UBYTE *                GetSaveName(VOID);
  75. UBYTE *                GetRestoreName(VOID);
  76. VOID                ConPutC(UBYTE c);
  77. UBYTE                ConGetC(VOID);
  78. VOID                ConPutS(UBYTE *s);
  79. VOID                ConPrintf(UBYTE *Text,...);
  80. VOID                ConPutS2(UBYTE *a,UBYTE *b);
  81. VOID                ConCleanup(VOID);
  82. BYTE                OpenConsoleStuff(VOID);
  83.  
  84. extern struct WBStartup        *WBenchMsg;
  85. extern UBYTE            *ProgramName;
  86. extern char            *story_name,
  87.                  print_name[];
  88. extern int             printer_width;
  89.  
  90. STATIC UBYTE            *VersionTag = VERSTAG;
  91.  
  92. struct IntuitionBase        *IntuitionBase;
  93. struct GfxBase            *GfxBase;
  94. struct Library            *GadToolsBase;
  95. struct Library            *AslBase;
  96. struct Library            *WorkbenchBase;
  97. struct Library            *IconBase;
  98. struct Library            *IFFParseBase;
  99. struct Library            *TranslatorBase;
  100.  
  101. STATIC struct MsgPort        *SpeechPort;
  102. STATIC struct Process        *SpeechProcess;
  103. STATIC BYTE             NarrateStory = FALSE;
  104.  
  105. STATIC struct FileRequester    *SaveRequest,
  106.                 *RestoreRequest,
  107.                 *ProtocolRequest;
  108.  
  109. struct Screen            *Screen;
  110. STATIC struct Menu        *MachineMenu;
  111. STATIC APTR             VisualInfo;
  112.  
  113. struct Process            *ThisProcess;
  114. STATIC APTR             OldPtr;
  115.  
  116. STATIC struct IOStdReq        *ConReadRequest,
  117.                 *ConWriteRequest;
  118.  
  119. STATIC struct MsgPort        *ConWritePort,
  120.                 *ConReadPort;
  121.  
  122. STATIC struct MsgPort        *WorkbenchPort;
  123. STATIC struct AppWindow        *WorkbenchWindow;
  124.  
  125. STATIC UBYTE             ScreenTitle[80],
  126.                   SharedBuffer[256];
  127.  
  128. STATIC struct Window        *DebugWindow;
  129. STATIC BPTR             DebugFile;
  130. STATIC struct MenuItem        *DebugItem;
  131. STATIC LONG             DebugX = -1,DebugY = -1,DebugWidth = -1,DebugHeight = -1;
  132.  
  133. UBYTE                *String = NULL;
  134. UBYTE                 LastFile[256];
  135. BYTE                 DontAsk = FALSE;
  136. BYTE                 CustomScreen = FALSE;
  137. struct Window            *Window;
  138. UWORD                 TwoColours[2];
  139.  
  140. struct TextAttr             DefaultFont;
  141. UBYTE                 DefaultFontName[256];
  142. UWORD                 DefaultFontWidth;
  143.  
  144. STATIC UWORD __chip Stopwatch[(2 + 16) * 2] =
  145. {
  146.     0x0000,0x0000,
  147.  
  148.     0x0400,0x07C0,
  149.     0x0000,0x07C0,
  150.     0x0100,0x0380,
  151.     0x0000,0x07E0,
  152.     0x07C0,0x1FF8,
  153.     0x1FF0,0x3FEC,
  154.     0x3FF8,0x7FDE,
  155.     0x3FF8,0x7FBE,
  156.     0x7FFC,0xFF7F,
  157.     0x7EFC,0xFFFF,
  158.     0x7FFC,0xFFFF,
  159.     0x3FF8,0x7FFE,
  160.     0x3FF8,0x7FFE,
  161.     0x1FF0,0x3FFC,
  162.     0x07C0,0x1FF8,
  163.     0x0000,0x07E0,
  164.  
  165.     0x0000,0x0000
  166. };
  167.  
  168. STATIC UBYTE *MenuCodes[] =
  169. {
  170.     "",
  171.     "save\r", "save\r", "restore\r", "script", "palette", "about\r", "quit\r",
  172.     "look\r", "wait\r", "inventory\r", "diagnose\r",
  173.     "restart\r", "verbose\r", "brief\r", "superbrief\r", "score\r", "time\r", "",
  174.     "north\r", "east\r", "south\r", "west\r", "northeast\r", "southeast\r", "southwest\r", "northwest\r", "up\r", "down\r", "in\r", "out\r",
  175.     "$verify\r", "version\r", ""
  176. };
  177.  
  178. STATIC struct NewMenu MachineMenuConfig[] =
  179. {
  180.     { NM_TITLE, "Project",             0 ,0,            0,    (APTR)0},
  181.     {  NM_ITEM, "Save",            "S",0,            0,    (APTR)MEN_SAVE},
  182.     {  NM_ITEM, "Save As...",        "A",0,            0,    (APTR)MEN_SAVEAS},
  183.     {  NM_ITEM, "Open...",            "O",0,            0,    (APTR)MEN_RESTORE},
  184.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  185.     {  NM_ITEM, "Protocol",            "P",CHECKIT|MENUTOGGLE,    0,    (APTR)MEN_SCRIPT},
  186.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  187.     {  NM_ITEM, "Palette",             0 ,0,            0,    (APTR)MEN_PALETTE},
  188.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  189.     {  NM_ITEM, "About...",            "?",0,            0,    (APTR)MEN_ABOUT},
  190.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  191.     {  NM_ITEM, "Quit...",            "Q",0,            0,    (APTR)MEN_QUIT},
  192.  
  193.     { NM_TITLE, "Commands",             0 ,0,            0,    (APTR)0},
  194.     {  NM_ITEM, "Look",            "L",0,            0,    (APTR)MEN_LOOK},
  195.     {  NM_ITEM, "Wait",            "W",0,            0,    (APTR)MEN_WAIT},
  196.     {  NM_ITEM, "Inventory",        "I",0,            0,    (APTR)MEN_INVENTORY},
  197.     {  NM_ITEM, "Diagnose",            "D",0,            0,    (APTR)MEN_DIAGNOSE},
  198.  
  199.     { NM_TITLE, "Story",             0 ,0,            0,    (APTR)0},
  200.     {  NM_ITEM, "Restart...",        "R",0,            0,    (APTR)MEN_RESTART},
  201.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  202.     {  NM_ITEM, "Verbose",            ",",CHECKIT,        ~4,    (APTR)MEN_VERBOSE},
  203.     {  NM_ITEM, "Brief",            "0",CHECKIT|CHECKED,    ~8,    (APTR)MEN_BRIEF},
  204.     {  NM_ITEM, "Superbrief",        ".",CHECKIT,        ~16,    (APTR)MEN_SUPERBRIEF},
  205.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  206.     {  NM_ITEM, "Score",            "Z",0,            0,    (APTR)MEN_SCORE},
  207.     {  NM_ITEM, "Time",            "T",0,            0,    (APTR)MEN_TIME},
  208.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  209.     {  NM_ITEM, "Narrate story",        "N",CHECKIT|MENUTOGGLE,    0,    (APTR)MEN_SPEECH},
  210.  
  211.     { NM_TITLE, "Movement",             0 ,0,            0,    (APTR)0},
  212.     {  NM_ITEM, "North",            "8",0,            0,    (APTR)MEN_NORTH},
  213.     {  NM_ITEM, "East",            "6",0,            0,    (APTR)MEN_EAST},
  214.     {  NM_ITEM, "South",            "2",0,            0,    (APTR)MEN_SOUTH},
  215.     {  NM_ITEM, "West",            "4",0,            0,    (APTR)MEN_WEST},
  216.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  217.     {  NM_ITEM, "Northeast",        "9",0,            0,    (APTR)MEN_NORTHEAST},
  218.     {  NM_ITEM, "Southeast",        "3",0,            0,    (APTR)MEN_SOUTHEAST},
  219.     {  NM_ITEM, "Southwest",        "1",0,            0,    (APTR)MEN_SOUTHWEST},
  220.     {  NM_ITEM, "Northwest",        "7",0,            0,    (APTR)MEN_NORTHWEST},
  221.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  222.     {  NM_ITEM, "Up",            "+",0,            0,    (APTR)MEN_UP},
  223.     {  NM_ITEM, "Down",            "-",0,            0,    (APTR)MEN_DOWN},
  224.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  225.     {  NM_ITEM, "In",            "<",0,            0,    (APTR)MEN_IN},
  226.     {  NM_ITEM, "Out",            ">",0,            0,    (APTR)MEN_OUT},
  227.  
  228.     { NM_TITLE, "Diagnose",             0 ,0,            0,    (APTR)0},
  229.     {  NM_ITEM, "Verify disk",         0 ,0,            0,    (APTR)MEN_VERIFY},
  230.     {  NM_ITEM, "Version",             0 ,0,            0,    (APTR)MEN_VERSION},
  231.     {  NM_ITEM, NM_BARLABEL,         0 ,0,            0,    (APTR)0},
  232.     {  NM_ITEM, "Debug mode",         0 ,CHECKIT|MENUTOGGLE,    0,    (APTR)MEN_DEBUG},
  233.  
  234.     { NM_END, 0,                 0 ,0,            0,    (APTR)0}
  235. };
  236.  
  237. VOID
  238. AdjustTitle(STRPTR Title)
  239. {
  240.     if(!Screen)
  241.     {
  242.         STATIC UBYTE Title1[256],Title2[256];
  243.  
  244.         if(Title)
  245.             strcpy((char *)Title1,(char *)Title);
  246.  
  247.         Title = Title1;
  248.  
  249.         if(NarrateStory && SpeechProcess)
  250.             sprintf(Title2,"%s (narrating)",Title);
  251.         else
  252.             strcpy((char *)Title2,(char *)Title);
  253.  
  254.         SetWindowTitles(Window,Title2,(UBYTE *)-1);
  255.     }
  256. }
  257.  
  258. LONG
  259. ahtoi(STRPTR String)
  260. {
  261.     LONG Value = 0;
  262.     UBYTE c;
  263.  
  264.     while(c = *String)
  265.     {
  266.         Value <<= 4;
  267.  
  268.         if(c >= '0' && c <= '9')
  269.             Value |= (c & 15);
  270.         else
  271.             Value |= (c & 15) + 9;
  272.  
  273.         ++String;
  274.     }
  275.  
  276.     return(Value);
  277. }
  278.  
  279. VOID
  280. CloseDebugWindow()
  281. {
  282.     if(DebugWindow)
  283.     {
  284.         DebugX        = DebugWindow -> LeftEdge;
  285.         DebugY        = DebugWindow -> TopEdge;
  286.         DebugWidth    = DebugWindow -> Width;
  287.         DebugHeight    = DebugWindow -> Height;
  288.  
  289.         if(DebugFile)
  290.             FreeSignal(DebugWindow -> UserPort -> mp_SigBit);
  291.         else
  292.             CloseWindow(DebugWindow);
  293.  
  294.         DebugWindow = NULL;
  295.     }
  296.  
  297.     if(DebugFile)
  298.     {
  299.         Close(DebugFile);
  300.  
  301.         DebugFile = NULL;
  302.     }
  303.  
  304.     if(DebugItem)
  305.         DebugItem -> Flags &= ~CHECKED;
  306. }
  307.  
  308. BYTE
  309. OpenDebug()
  310. {
  311.     if(DebugWidth == -1)
  312.     {
  313.         DebugWindow = OpenWindowTags(NULL,
  314.             WA_Top,            Window -> TopEdge    + 20,
  315.             WA_Left,        Window -> LeftEdge    + 20,
  316.             WA_InnerWidth,        GfxBase -> DefaultFont -> tf_XSize * 40,
  317.             WA_InnerHeight,        GfxBase -> DefaultFont -> tf_YSize * 10,
  318.             WA_Title,        "Debug Window",
  319.             WA_MaxWidth,        Window -> WScreen -> Width,
  320.             WA_MaxHeight,        Window -> WScreen -> Height,
  321.             WA_CloseGadget,        TRUE,
  322.             WA_IDCMP,        IDCMP_CLOSEWINDOW,
  323.             WA_SimpleRefresh,    TRUE,
  324.             WA_SizeBBottom,        TRUE,
  325.             WA_SizeGadget,        TRUE,
  326.             WA_DragBar,        TRUE,
  327.             WA_DepthGadget,        TRUE,
  328.             WA_RMBTrap,        TRUE,
  329.             WA_CustomScreen,    Window -> WScreen,
  330.         TAG_DONE);
  331.     }
  332.     else
  333.     {
  334.         DebugWindow = OpenWindowTags(NULL,
  335.             WA_Top,            DebugY,
  336.             WA_Left,        DebugX,
  337.             WA_Width,        DebugWidth,
  338.             WA_Height,        DebugHeight,
  339.             WA_Title,        "Debug Window",
  340.             WA_MaxWidth,        Window -> WScreen -> Width,
  341.             WA_MaxHeight,        Window -> WScreen -> Height,
  342.             WA_CloseGadget,        TRUE,
  343.             WA_IDCMP,        IDCMP_CLOSEWINDOW,
  344.             WA_SimpleRefresh,    TRUE,
  345.             WA_SizeGadget,        TRUE,
  346.             WA_DragBar,        TRUE,
  347.             WA_DepthGadget,        TRUE,
  348.             WA_RMBTrap,        TRUE,
  349.             WA_CustomScreen,    Window -> WScreen,
  350.         TAG_DONE);
  351.     }
  352.  
  353.     if(DebugWindow)
  354.     {
  355.         UBYTE Buffer[40];
  356.  
  357.         sprintf(Buffer,"CON://///INACTIVE/WINDOW%08lx",DebugWindow);
  358.  
  359.         if(DebugFile = Open(Buffer,MODE_READWRITE))
  360.             return(TRUE);
  361.  
  362.         CloseWindow(DebugWindow);
  363.     }
  364.  
  365.     DebugWindow = NULL;
  366.  
  367.     return(FALSE);
  368. }
  369.  
  370. VOID
  371. DPrintf(STRPTR Format,...)
  372. {
  373.     if(DebugFile)
  374.     {
  375.         if(Format[0])
  376.         {
  377.             va_list VarArgs;
  378.  
  379.             va_start(VarArgs,Format);
  380.             VFPrintf(DebugFile,Format,(APTR)VarArgs);
  381.             va_end(VarArgs);
  382.         }
  383.         else
  384.             Flush(DebugFile);
  385.  
  386.         if(SetSignal(0,0) & SIG_DEBUG)
  387.         {
  388.             struct IntuiMessage *Message;
  389.  
  390.             while(Message = (struct IntuiMessage *)GetMsg(DebugWindow -> UserPort))
  391.                 ReplyMsg((struct Message *)Message);
  392.  
  393.             SetSignal(0,SIG_DEBUG);
  394.  
  395.             CloseDebugWindow();
  396.         }
  397.     }
  398. }
  399.  
  400. VOID
  401. SayMore(UBYTE *a,UBYTE *b)
  402. {
  403.     if(SpeechPort && NarrateStory)
  404.     {
  405.         struct Message    *Msg;
  406.         WORD         Len = b - a;
  407.  
  408.         if(b[-1] == '>')
  409.             Len--;
  410.  
  411.         if(Len > 0)
  412.         {
  413.             if(Msg = (struct Message *)AllocVec(sizeof(struct Message) + Len + 1,MEMF_ANY | MEMF_PUBLIC | MEMF_CLEAR))
  414.             {
  415.                 Msg -> mn_Node . ln_Name    = (STRPTR)(Msg + 1);
  416.                 Msg -> mn_Length        = sizeof(struct Message) + Len + 1;
  417.  
  418.                 memcpy(Msg -> mn_Node . ln_Name,a,Len);
  419.  
  420.                 PutMsg(SpeechPort,Msg);
  421.             }
  422.         }
  423.     }
  424. }
  425.  
  426. VOID __saveds
  427. SpeechServer()
  428. {
  429.     struct MsgPort        *NarratorPort;
  430.     struct narrator_rb    *NarratorRequest;
  431.     STRPTR             TranslateBuffer;
  432.  
  433. #ifdef AZTEC_C
  434.     geta4();
  435. #endif    /* AZTEC_C */
  436.  
  437.     if(TranslateBuffer = (STRPTR)AllocVec(10000,MEMF_ANY))
  438.     {
  439.         if(NarratorPort = CreateMsgPort())
  440.         {
  441.             if(NarratorRequest = (struct narrator_rb *)CreateIORequest(NarratorPort,sizeof(struct narrator_rb)))
  442.             {
  443.                 STATIC UBYTE AnyChannel[4] = { 1,8,2,4 };
  444.  
  445.                 NarratorRequest -> ch_masks        = &AnyChannel[0];
  446.                 NarratorRequest -> nm_masks        = 4;
  447.  
  448.                 NarratorRequest -> message . io_Command    = CMD_WRITE;
  449.                 NarratorRequest -> message . io_Data    = (APTR)TranslateBuffer;
  450.  
  451.                 if(!OpenDevice("narrator.device",0,(struct IORequest *)NarratorRequest,0))
  452.                 {
  453.                     if(SpeechPort = CreateMsgPort())
  454.                     {
  455.                         struct Message    *Msg;
  456.                         ULONG         SignalSet;
  457.                         BYTE         Terminated = FALSE;
  458.  
  459.                         Signal((struct Task *)ThisProcess,SIG_HANDSHAKE);
  460.  
  461.                         while(!Terminated)
  462.                         {
  463.                             SignalSet = Wait(SIG_TEXT | SIG_KILL);
  464.  
  465.                             if(SignalSet & SIG_KILL)
  466.                                 break;
  467.  
  468.                             if(SignalSet & SIG_TEXT)
  469.                             {
  470.                                 if(NarrateStory)
  471.                                 {
  472.                                     SetSignal(0,SIG_STOP);
  473.  
  474.                                     while(Msg = GetMsg(SpeechPort))
  475.                                     {
  476.                                         if(!Translate(Msg -> mn_Node . ln_Name,strlen((char *)Msg -> mn_Node . ln_Name),TranslateBuffer,9999))
  477.                                         {
  478.                                             NarratorRequest -> message . io_Length = strlen((char *)TranslateBuffer);
  479.  
  480.                                             BeginIO(NarratorRequest);
  481.  
  482.                                             FOREVER
  483.                                             {
  484.                                                 SignalSet = Wait(SIG_KILL | SIG_STOP | SIG_SPEECH);
  485.  
  486.                                                 if(SignalSet & SIG_KILL)
  487.                                                 {
  488.                                                     if(!CheckIO((struct IORequest *)NarratorRequest))
  489.                                                         AbortIO((struct IORequest *)NarratorRequest);
  490.  
  491.                                                     WaitIO((struct IORequest *)NarratorRequest);
  492.  
  493.                                                     Terminated = TRUE;
  494.  
  495.                                                     break;
  496.                                                 }
  497.  
  498.                                                 if(SignalSet & SIG_STOP)
  499.                                                 {
  500.                                                     if(!CheckIO((struct IORequest *)NarratorRequest))
  501.                                                         AbortIO((struct IORequest *)NarratorRequest);
  502.  
  503.                                                     WaitIO((struct IORequest *)NarratorRequest);
  504.  
  505.                                                     while(Msg = GetMsg(SpeechPort))
  506.                                                         FreeVec(Msg);
  507.  
  508.                                                     break;
  509.                                                 }
  510.  
  511.                                                 if(SignalSet & SIG_SPEECH)
  512.                                                 {
  513.                                                     WaitIO((struct IORequest *)NarratorRequest);
  514.  
  515.                                                     break;
  516.                                                 }
  517.                                             }
  518.                                         }
  519.  
  520.                                         FreeVec(Msg);
  521.  
  522.                                         if(Terminated)
  523.                                             break;
  524.                                     }
  525.                                 }
  526.                                 else
  527.                                 {
  528.                                     while(Msg = GetMsg(SpeechPort))
  529.                                         FreeVec(Msg);
  530.                                 }
  531.                             }
  532.                         }
  533.  
  534.                         while(Msg = GetMsg(SpeechPort))
  535.                             FreeVec(Msg);
  536.  
  537.                         DeleteMsgPort(SpeechPort);
  538.  
  539.                         SpeechPort = NULL;
  540.                     }
  541.  
  542.                     CloseDevice((struct IORequest *)NarratorRequest);
  543.                 }
  544.  
  545.                 DeleteIORequest(NarratorRequest);
  546.             }
  547.  
  548.             DeleteMsgPort(NarratorPort);
  549.         }
  550.  
  551.         FreeVec(TranslateBuffer);
  552.     }
  553.  
  554.     Forbid();
  555.  
  556.     SpeechProcess = NULL;
  557.  
  558.     Signal((struct Task *)ThisProcess,SIG_HANDSHAKE);
  559. }
  560.  
  561. VOID
  562. DeleteSpeech()
  563. {
  564.     if(SpeechProcess)
  565.     {
  566.         Signal((struct Task *)SpeechProcess,SIG_KILL);
  567.  
  568.         Wait(SIG_HANDSHAKE);
  569.     }
  570.  
  571.     if(TranslatorBase)
  572.     {
  573.         CloseLibrary((struct Library *)TranslatorBase);
  574.  
  575.         TranslatorBase = NULL;
  576.     }
  577. }
  578.  
  579. BYTE
  580. CreateSpeech()
  581. {
  582.     if(TranslatorBase = OpenLibrary("translator.library",37))
  583.     {
  584.         if(SpeechProcess = CreateNewProcTags(
  585.             NP_Name,    "Zorkmachine Speech",
  586.             NP_StackSize,    8192,
  587.             NP_Priority,    5,
  588.             NP_WindowPtr,    -1,
  589.             NP_Entry,    SpeechServer,
  590.         TAG_DONE))
  591.         {
  592.             Wait(SIG_HANDSHAKE);
  593.  
  594.             if(SpeechProcess)
  595.                 return(TRUE);
  596.         }
  597.     }
  598.  
  599.     DeleteSpeech();
  600.  
  601.     return(FALSE);
  602. }
  603.  
  604. VOID
  605. BlockWindow()
  606. {
  607.     SetPointer(Window,&Stopwatch[0],16,16,-6,0);
  608.  
  609.     Window -> Flags |= WFLG_RMBTRAP;
  610.  
  611.     if(DebugWindow)
  612.         SetPointer(DebugWindow,&Stopwatch[0],16,16,-6,0);
  613. }
  614.  
  615. VOID
  616. UnblockWindow()
  617. {
  618.     ClearPointer(Window);
  619.  
  620.     Window -> Flags &= ~WFLG_RMBTRAP;
  621.  
  622.     if(DebugWindow)
  623.         ClearPointer(DebugWindow);
  624. }
  625.  
  626. BOOL
  627. ShowRequest(UBYTE *Text,UBYTE *Gadgets,...)
  628. {
  629.     struct EasyStruct    Easy;
  630.     BOOL            Result;
  631.     ULONG            IDCMP = NULL;
  632.     va_list             VarArgs;
  633.  
  634.     Easy . es_StructSize    = sizeof(struct EasyStruct);
  635.     Easy . es_Flags        = NULL;
  636.     Easy . es_Title        = (UBYTE *)ProgramName;
  637.     Easy . es_TextFormat    = (UBYTE *)Text;
  638.     Easy . es_GadgetFormat    = (UBYTE *)Gadgets;
  639.  
  640.     BlockWindow();
  641.  
  642.     va_start(VarArgs,Gadgets);
  643.     Result = EasyRequestArgs(Window,&Easy,&IDCMP,VarArgs);
  644.     va_end(VarArgs);
  645.  
  646.     UnblockWindow();
  647.  
  648.     return(Result);
  649. }
  650.  
  651. struct Gadget *
  652. CreateAllPaletteGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge,UWORD Width)
  653. {
  654.     struct Gadget        *Gadget;
  655.     struct NewGadget     NewGadget;
  656.     UWORD             Counter = 0;
  657.  
  658.     memset(&NewGadget,0,sizeof(struct NewGadget));
  659.  
  660.     if(Gadget = CreateContext(GadgetList))
  661.     {
  662.         NewGadget . ng_GadgetText    = "Palette";
  663.         NewGadget . ng_TextAttr        = &DefaultFont;
  664.         NewGadget . ng_VisualInfo    = VisualInfo;
  665.         NewGadget . ng_GadgetID        = Counter;
  666.         NewGadget . ng_Flags        = PLACETEXT_LEFT;
  667.         NewGadget . ng_LeftEdge        = 10 + 9 * DefaultFontWidth;
  668.         NewGadget . ng_TopEdge        = 1 + TopEdge;
  669.         NewGadget . ng_Width        = 20 * DefaultFontWidth;
  670.         NewGadget . ng_Height        = DefaultFont . ta_YSize * 3;
  671.  
  672.         GadgetArray[Counter++] = Gadget = CreateGadget(PALETTE_KIND,Gadget,&NewGadget,
  673.             GTPA_Depth,        1,
  674.             GTPA_Color,        0,
  675.             GTPA_IndicatorWidth,    NewGadget . ng_Width / (1 << 2),
  676.             GTPA_IndicatorHeight,    NewGadget . ng_Height,
  677.         TAG_DONE);
  678.  
  679.         NewGadget . ng_GadgetText    = "Red   ";
  680.         NewGadget . ng_GadgetID        = Counter;
  681.         NewGadget . ng_TopEdge        = NewGadget . ng_TopEdge + NewGadget . ng_Height + INTERHEIGHT;
  682.         NewGadget . ng_Height        = DefaultFont . ta_YSize + 2;
  683.  
  684.         GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
  685.             GTSL_Min,        0,
  686.             GTSL_Max,        15,
  687.             GTSL_Level,        0,
  688.             GTSL_LevelFormat,    "%2ld",
  689.             GTSL_MaxLevelLen,    2,
  690.         TAG_DONE);
  691.  
  692.         NewGadget . ng_GadgetText    = "Green   ";
  693.         NewGadget . ng_GadgetID        = Counter;
  694.         NewGadget . ng_TopEdge        = NewGadget . ng_TopEdge + NewGadget . ng_Height + INTERHEIGHT;
  695.  
  696.         GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
  697.             GTSL_Min,        0,
  698.             GTSL_Max,        15,
  699.             GTSL_Level,        0,
  700.             GTSL_LevelFormat,    "%2ld",
  701.             GTSL_MaxLevelLen,    2,
  702.         TAG_DONE);
  703.  
  704.         NewGadget . ng_GadgetText    = "Blue   ";
  705.         NewGadget . ng_GadgetID        = Counter;
  706.         NewGadget . ng_TopEdge        = NewGadget . ng_TopEdge + NewGadget . ng_Height + INTERHEIGHT;
  707.  
  708.         GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
  709.             GTSL_Min,        0,
  710.             GTSL_Max,        15,
  711.             GTSL_Level,        0,
  712.             GTSL_LevelFormat,    "%2ld",
  713.             GTSL_MaxLevelLen,    2,
  714.         TAG_DONE);
  715.  
  716.         NewGadget . ng_GadgetText    = "Okay";
  717.         NewGadget . ng_GadgetID        = Counter;
  718.         NewGadget . ng_Flags        = NULL;
  719.         NewGadget . ng_LeftEdge        = 10;
  720.         NewGadget . ng_TopEdge        = NewGadget . ng_TopEdge + NewGadget . ng_Height + INTERHEIGHT;
  721.         NewGadget . ng_Width        = 11 * DefaultFontWidth + 8;
  722.         NewGadget . ng_Height        = DefaultFont . ta_YSize + 6;
  723.  
  724.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  725.             TAG_DONE);
  726.  
  727.         NewGadget . ng_GadgetText    = "Cancel";
  728.         NewGadget . ng_GadgetID        = Counter;
  729.         NewGadget . ng_LeftEdge        = Width - 10 - NewGadget . ng_Width;
  730.  
  731.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  732.             TAG_DONE);
  733.     }
  734.  
  735.     return(Gadget);
  736. }
  737.  
  738. VOID
  739. EditPalette()
  740. {
  741.     struct Gadget        *GadgetList,
  742.                 *GadgetArray[6];
  743.  
  744.     struct Window        *LocalWindow;
  745.     struct Requester     GlobalRequester;
  746.  
  747.     WORD             Width    = 2 * 10 + 20 * DefaultFontWidth + 9 * DefaultFontWidth,
  748.                  Height    = 1 + Window -> WScreen -> WBorTop + Window -> WScreen -> Font -> ta_YSize + 1 + DefaultFont . ta_YSize * 3 + INTERHEIGHT + 3 * (DefaultFont . ta_YSize + 2 + INTERHEIGHT) + DefaultFont . ta_YSize + 6 + INTERHEIGHT,
  749.                  i;
  750.  
  751.     UWORD             NewPalette[2],
  752.                  OldPalette[2],
  753.                  R,G,B;
  754.  
  755.     for(i = 0 ; i < 2 ; i++)
  756.         NewPalette[i] = OldPalette[i] = GetRGB4(Window -> WScreen -> ViewPort . ColorMap,i);
  757.  
  758.     SetPointer(Window,&Stopwatch[0],16,16,-6,0);
  759.  
  760.     memset(&GlobalRequester,0,sizeof(struct Requester));
  761.  
  762.     Request(&GlobalRequester,Window);
  763.  
  764.     if(CreateAllPaletteGadgets(&GadgetArray[0],&GadgetList,VisualInfo,Window -> WScreen -> WBorTop + Window -> WScreen -> Font -> ta_YSize + 1,Width))
  765.     {
  766.         if(LocalWindow = OpenWindowTags(NULL,
  767.             WA_Top,            Window -> TopEdge + (Window -> Height - Height) / 2,
  768.             WA_Left,        Window -> LeftEdge + (Window -> Width - Width) / 2,
  769.             WA_Title,        "Palette",
  770.             WA_Width,        Width,
  771.             WA_Height,        Height,
  772.             WA_IDCMP,        IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | PALETTEIDCMP | SLIDERIDCMP | BUTTONIDCMP,
  773.             WA_Activate,        TRUE,
  774.             WA_CloseGadget,        TRUE,
  775.             WA_DragBar,        TRUE,
  776.             WA_DepthGadget,        TRUE,
  777.             WA_RMBTrap,        TRUE,
  778.             WA_CustomScreen,    Window -> WScreen,
  779.         TAG_DONE))
  780.         {
  781.             struct IntuiMessage    *Massage;
  782.             ULONG             Class,
  783.                          Code;
  784.             struct Gadget        *Gadget;
  785.  
  786.             BYTE             Terminated = FALSE;
  787.             WORD             Active = 0;
  788.  
  789.             AddGList(LocalWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  790.             RefreshGList(GadgetList,LocalWindow,NULL,(UWORD)-1);
  791.             GT_RefreshWindow(LocalWindow,NULL);
  792.  
  793.             R = (OldPalette[0] >> 8) & 0xF;
  794.             G = (OldPalette[0] >> 4) & 0xF;
  795.             B = (OldPalette[0]     ) & 0xF;
  796.  
  797.             GT_SetGadgetAttrs(GadgetArray[GAD_PALETTE_RED],LocalWindow,NULL,
  798.                 GTSL_Level,R,
  799.             TAG_DONE);
  800.  
  801.             GT_SetGadgetAttrs(GadgetArray[GAD_PALETTE_GREEN],LocalWindow,NULL,
  802.                 GTSL_Level,G,
  803.             TAG_DONE);
  804.  
  805.             GT_SetGadgetAttrs(GadgetArray[GAD_PALETTE_BLUE],LocalWindow,NULL,
  806.                 GTSL_Level,B,
  807.             TAG_DONE);
  808.  
  809.             while(!Terminated)
  810.             {
  811.                 WaitPort(LocalWindow -> UserPort);
  812.  
  813.                 while(Massage = GT_GetIMsg(LocalWindow -> UserPort))
  814.                 {
  815.                     Class    = Massage -> Class;
  816.                     Code    = Massage -> Code;
  817.                     Gadget    = (struct Gadget *)Massage -> IAddress;
  818.  
  819.                     GT_ReplyIMsg(Massage);
  820.  
  821.                     switch(Class)
  822.                     {
  823.                         case IDCMP_CLOSEWINDOW:        Terminated = TRUE;
  824.                                         break;
  825.  
  826.                         case IDCMP_MOUSEMOVE:        switch(Gadget -> GadgetID)
  827.                                         {
  828.                                             case GAD_PALETTE_RED:    R = Code;
  829.  
  830.                                                         NewPalette[Active] = (R << 8) | (G << 4) | B;
  831.  
  832.                                                         SetRGB4(&Window -> WScreen -> ViewPort,Active,R,G,B);
  833.  
  834.                                                         break;
  835.  
  836.                                             case GAD_PALETTE_GREEN:    G = Code;
  837.  
  838.                                                         NewPalette[Active] = (R << 8) | (G << 4) | B;
  839.  
  840.                                                         SetRGB4(&Window -> WScreen -> ViewPort,Active,R,G,B);
  841.  
  842.                                                         break;
  843.  
  844.                                             case GAD_PALETTE_BLUE:    B = Code;
  845.  
  846.                                                         NewPalette[Active] = (R << 8) | (G << 4) | B;
  847.  
  848.                                                         SetRGB4(&Window -> WScreen -> ViewPort,Active,R,G,B);
  849.  
  850.                                                         break;
  851.                                         }
  852.  
  853.                                         break;
  854.  
  855.                         case IDCMP_GADGETUP:        switch(Gadget -> GadgetID)
  856.                                         {
  857.                                             case GAD_PALETTE_RED:    R = Code;
  858.  
  859.                                                         NewPalette[Active] = (R << 8) | (G << 4) | B;
  860.  
  861.                                                         SetRGB4(&Window -> WScreen -> ViewPort,Active,R,G,B);
  862.  
  863.                                                         break;
  864.  
  865.                                             case GAD_PALETTE_GREEN:    G = Code;
  866.  
  867.                                                         NewPalette[Active] = (R << 8) | (G << 4) | B;
  868.  
  869.                                                         SetRGB4(&Window -> WScreen -> ViewPort,Active,R,G,B);
  870.  
  871.                                                         break;
  872.  
  873.                                             case GAD_PALETTE_BLUE:    B = Code;
  874.  
  875.                                                         NewPalette[Active] = (R << 8) | (G << 4) | B;
  876.  
  877.                                                         SetRGB4(&Window -> WScreen -> ViewPort,Active,R,G,B);
  878.  
  879.                                                         break;
  880.  
  881.                                             case GAD_PALETTE_COLOURS:
  882.  
  883.                                                         Active = Code;
  884.  
  885.                                                         R = (NewPalette[Active] >> 8) & 0xF;
  886.                                                         G = (NewPalette[Active] >> 4) & 0xF;
  887.                                                         B = (NewPalette[Active]     ) & 0xF;
  888.  
  889.                                                         GT_SetGadgetAttrs(GadgetArray[GAD_PALETTE_RED],LocalWindow,NULL,
  890.                                                             GTSL_Level,R,
  891.                                                         TAG_DONE);
  892.  
  893.                                                         GT_SetGadgetAttrs(GadgetArray[GAD_PALETTE_GREEN],LocalWindow,NULL,
  894.                                                             GTSL_Level,G,
  895.                                                         TAG_DONE);
  896.  
  897.                                                         GT_SetGadgetAttrs(GadgetArray[GAD_PALETTE_BLUE],LocalWindow,NULL,
  898.                                                             GTSL_Level,B,
  899.                                                         TAG_DONE);
  900.  
  901.                                                         break;
  902.  
  903.                                             case GAD_PALETTE_CANCEL:
  904.  
  905.                                                         LoadRGB4(&Window -> WScreen -> ViewPort,OldPalette,2);
  906.  
  907.                                             case GAD_PALETTE_USE:    Terminated = TRUE;
  908.  
  909.                                                         break;
  910.                                         }
  911.  
  912.                                         break;
  913.                     }
  914.                 }
  915.             }
  916.  
  917.             CloseWindow(LocalWindow);
  918.         }
  919.  
  920.         FreeGadgets(GadgetList);
  921.     }
  922.  
  923.     EndRequest(&GlobalRequester,Window);
  924.  
  925.     ClearPointer(Window);
  926. }
  927.  
  928. struct Gadget *
  929. CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
  930. {
  931.     struct Gadget        *Gadget;
  932.     struct NewGadget     NewGadget;
  933.     UWORD             Counter = 0;
  934.  
  935.     memset(&NewGadget,0,sizeof(struct NewGadget));
  936.  
  937.     if(Gadget = CreateContext(GadgetList))
  938.     {
  939.         WORD InterWidth;
  940.  
  941.         NewGadget . ng_GadgetText    = "Protocol output file/device";
  942.         NewGadget . ng_TextAttr        = &DefaultFont;
  943.         NewGadget . ng_VisualInfo    = VisualInfo;
  944.         NewGadget . ng_GadgetID        = Counter;
  945.         NewGadget . ng_Flags        = PLACETEXT_ABOVE;
  946.         NewGadget . ng_LeftEdge        = 10;
  947.         NewGadget . ng_TopEdge        = 1 + TopEdge + 2 * INTERHEIGHT + DefaultFont . ta_YSize;
  948.         NewGadget . ng_Width        = 40 * DefaultFontWidth + 12;
  949.         NewGadget . ng_Height        = DefaultFont . ta_YSize + 6;
  950.  
  951.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  952.             GTST_MaxChars,    255,
  953.         TAG_DONE);
  954.  
  955.         NewGadget . ng_GadgetText    = "Protocol page width";
  956.         NewGadget . ng_GadgetID        = Counter;
  957.         NewGadget . ng_TopEdge        = NewGadget . ng_TopEdge + NewGadget . ng_Height + 2 * INTERHEIGHT + DefaultFont . ta_YSize;
  958.  
  959.         GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
  960.             GTIN_Number,    printer_width,
  961.         TAG_DONE);
  962.  
  963.         InterWidth = (NewGadget . ng_Width - 3 * (11 * DefaultFontWidth + 8)) / 2;
  964.  
  965.         NewGadget . ng_GadgetText    = "Okay";
  966.         NewGadget . ng_GadgetID        = Counter;
  967.         NewGadget . ng_Flags        = NULL;
  968.         NewGadget . ng_TopEdge        = NewGadget . ng_TopEdge + NewGadget . ng_Height + INTERHEIGHT;
  969.         NewGadget . ng_Width        = 11 * DefaultFontWidth + 8;
  970.         NewGadget . ng_Height        = DefaultFont . ta_YSize + 6;
  971.  
  972.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  973.             TAG_DONE);
  974.  
  975.         NewGadget . ng_GadgetText    = "Select File";
  976.         NewGadget . ng_GadgetID        = Counter;
  977.         NewGadget . ng_LeftEdge        = NewGadget . ng_LeftEdge + NewGadget . ng_Width + InterWidth;
  978.  
  979.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  980.             TAG_DONE);
  981.  
  982.         NewGadget . ng_GadgetText    = "Cancel";
  983.         NewGadget . ng_GadgetID        = Counter;
  984.         NewGadget . ng_LeftEdge        = NewGadget . ng_LeftEdge + NewGadget . ng_Width + InterWidth;
  985.  
  986.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  987.             TAG_DONE);
  988.     }
  989.  
  990.     return(Gadget);
  991. }
  992.  
  993. BYTE
  994. GetProtocolName(UBYTE *Name)
  995. {
  996.     struct Gadget        *GadgetList,
  997.                 *GadgetArray[5];
  998.  
  999.     struct Window        *LocalWindow;
  1000.     struct Requester     GlobalRequester;
  1001.  
  1002.     BYTE             Aborted = FALSE;
  1003.  
  1004.     SetPointer(Window,&Stopwatch[0],16,16,-6,0);
  1005.  
  1006.     memset(&GlobalRequester,0,sizeof(struct Requester));
  1007.  
  1008.     Request(&GlobalRequester,Window);
  1009.  
  1010.     if(CreateAllGadgets(&GadgetArray[0],&GadgetList,VisualInfo,Window -> WScreen -> WBorTop + Window -> WScreen -> Font -> ta_YSize + 1))
  1011.     {
  1012.         WORD    Width    = 2 * 10 + 40 * DefaultFontWidth + 12,
  1013.             Height    = 1 + Window -> WScreen -> WBorTop + Window -> WScreen -> Font -> ta_YSize + 1 + 4 * INTERHEIGHT + DefaultFont . ta_YSize + 2 * (DefaultFont . ta_YSize + 6) + Window -> WScreen -> WBorBottom + 2 * INTERHEIGHT + 2 * DefaultFont . ta_YSize + 6;
  1014.  
  1015.         if(LocalWindow = OpenWindowTags(NULL,
  1016.             WA_Top,            Window -> TopEdge + (Window -> Height - Height) / 2,
  1017.             WA_Left,        Window -> LeftEdge + (Window -> Width - Width) / 2,
  1018.             WA_Title,        "Open protocol",
  1019.             WA_Width,        Width,
  1020.             WA_Height,        Height,
  1021.             WA_IDCMP,        IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | STRINGIDCMP | BUTTONIDCMP,
  1022.             WA_Activate,        TRUE,
  1023.             WA_CloseGadget,        TRUE,
  1024.             WA_DragBar,        TRUE,
  1025.             WA_DepthGadget,        TRUE,
  1026.             WA_RMBTrap,        TRUE,
  1027.             WA_CustomScreen,    Window -> WScreen,
  1028.         TAG_DONE))
  1029.         {
  1030.             STATIC struct Requester     Requester;
  1031.  
  1032.             struct IntuiMessage    *Massage;
  1033.             ULONG             Class,
  1034.                          Code;
  1035.             struct Gadget        *Gadget;
  1036.  
  1037.             BYTE             Terminated = FALSE;
  1038.             UBYTE            *Buffer;
  1039.  
  1040.             AddGList(LocalWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  1041.             RefreshGList(GadgetList,LocalWindow,NULL,(UWORD)-1);
  1042.             GT_RefreshWindow(LocalWindow,NULL);
  1043.  
  1044.             GT_SetGadgetAttrs(GadgetArray[GAD_STRING],LocalWindow,NULL,
  1045.                 GTST_String,    Name,
  1046.             TAG_DONE);
  1047.  
  1048.             Buffer = GT_STRING(GadgetArray[GAD_STRING]);
  1049.  
  1050.             ActivateGadget(GadgetArray[GAD_STRING],LocalWindow,NULL);
  1051.  
  1052.             memset(&Requester,0,sizeof(struct Requester));
  1053.  
  1054.             while(!Terminated)
  1055.             {
  1056.                 WaitPort(LocalWindow -> UserPort);
  1057.  
  1058.                 while(Massage = GT_GetIMsg(LocalWindow -> UserPort))
  1059.                 {
  1060.                     Class    = Massage -> Class;
  1061.                     Code    = Massage -> Code;
  1062.                     Gadget    = (struct Gadget *)Massage -> IAddress;
  1063.  
  1064.                     GT_ReplyIMsg(Massage);
  1065.  
  1066.                     switch(Class)
  1067.                     {
  1068.                         case IDCMP_CLOSEWINDOW:        Aborted = Terminated = TRUE;
  1069.                                         break;
  1070.  
  1071.                         case IDCMP_ACTIVEWINDOW:    ActivateGadget(GadgetArray[GAD_STRING],LocalWindow,NULL);
  1072.                                         break;
  1073.  
  1074.                         case IDCMP_GADGETUP:        switch(Gadget -> GadgetID)
  1075.                                         {
  1076.                                             case GAD_ACCEPT:    if(Buffer[0])
  1077.                                                         {
  1078.                                                             strcpy((char *)Name,(char *)Buffer);
  1079.  
  1080.                                                             Terminated = TRUE;
  1081.  
  1082.                                                             if((printer_width = GT_INTEGER(GadgetArray[GAD_WIDTH])) < 40)
  1083.                                                                 printer_width = 40;
  1084.                                                         }
  1085.  
  1086.                                                         break;
  1087.  
  1088.                                             case GAD_SELECT:    Request(&Requester,LocalWindow);
  1089.  
  1090.                                                         SetPointer(LocalWindow,&Stopwatch[0],16,16,-6,0);
  1091.  
  1092.                                                         if(AslRequestTags(ProtocolRequest,TAG_DONE))
  1093.                                                         {
  1094.                                                             if(ProtocolRequest -> fr_File[0])
  1095.                                                             {
  1096.                                                                 strcpy((char *)SharedBuffer,(char *)ProtocolRequest -> fr_Drawer);
  1097.  
  1098.                                                                 if(AddPart(SharedBuffer,ProtocolRequest -> fr_File,256))
  1099.                                                                 {
  1100.                                                                     GT_SetGadgetAttrs(GadgetArray[GAD_STRING],LocalWindow,NULL,
  1101.                                                                         GTST_String,    SharedBuffer,
  1102.                                                                     TAG_DONE);
  1103.                                                                 }
  1104.                                                             }
  1105.                                                         }
  1106.  
  1107.                                                         ClearPointer(LocalWindow);
  1108.  
  1109.                                                         EndRequest(&Requester,LocalWindow);
  1110.  
  1111.                                                         break;
  1112.  
  1113.                                             case GAD_CANCEL:    Aborted = Terminated = TRUE;
  1114.                                                         break;
  1115.                                         }
  1116.  
  1117.                                         break;
  1118.                     }
  1119.                 }
  1120.             }
  1121.  
  1122.             CloseWindow(LocalWindow);
  1123.         }
  1124.  
  1125.         FreeGadgets(GadgetList);
  1126.     }
  1127.  
  1128.     EndRequest(&GlobalRequester,Window);
  1129.  
  1130.     ClearPointer(Window);
  1131.  
  1132.     return(Aborted);
  1133. }
  1134.  
  1135. UBYTE *
  1136. GetSaveName()
  1137. {
  1138.     UBYTE *Dummy;
  1139.  
  1140.     if(!LastFile[0])
  1141.     {
  1142.         if(!GetCurrentDirName(LastFile,256))
  1143.             LastFile[0] = 0;
  1144.  
  1145.         if(!AddPart(LastFile,"Story.Save",256))
  1146.             LastFile[0] = 0;
  1147.     }
  1148.  
  1149.     strcpy((char *)SharedBuffer,(char *)LastFile);
  1150.  
  1151.     if(Dummy = PathPart(SharedBuffer))
  1152.         *Dummy = 0;
  1153.  
  1154.     BlockWindow();
  1155.  
  1156.     if(AslRequestTags(SaveRequest,
  1157.         ASL_File,    FilePart(LastFile),
  1158.         ASL_Dir,    SharedBuffer,
  1159.     TAG_DONE))
  1160.     {
  1161.         if(SaveRequest -> fr_File[0])
  1162.         {
  1163.             strcpy((char *)SharedBuffer,(char *)SaveRequest -> fr_Drawer);
  1164.  
  1165.             if(AddPart(SharedBuffer,SaveRequest -> fr_File,256))
  1166.             {
  1167.                 BPTR FileLock;
  1168.  
  1169.                 if(FileLock = Lock(SharedBuffer,ACCESS_READ))
  1170.                 {
  1171.                     if(!ShowRequest("You are about to write over an existing file.","Proceed|Cancel"))
  1172.                     {
  1173.                         UnLock(FileLock);
  1174.  
  1175.                         UnblockWindow();
  1176.  
  1177.                         return(NULL);
  1178.                     }
  1179.  
  1180.                     UnLock(FileLock);
  1181.                 }
  1182.  
  1183.                 strcpy((char *)LastFile,(char *)SharedBuffer);
  1184.  
  1185.                 UnblockWindow();
  1186.  
  1187.                 return(LastFile);
  1188.             }
  1189.         }
  1190.     }
  1191.  
  1192.     UnblockWindow();
  1193.  
  1194.     return(NULL);
  1195. }
  1196.  
  1197. UBYTE *
  1198. GetRestoreName()
  1199. {
  1200.     UBYTE *Dummy;
  1201.  
  1202.     if(!LastFile[0])
  1203.     {
  1204.         if(!GetCurrentDirName(LastFile,256))
  1205.             LastFile[0] = 0;
  1206.  
  1207.         if(!AddPart(LastFile,"Story.Save",256))
  1208.             LastFile[0] = 0;
  1209.     }
  1210.  
  1211.     strcpy((char *)SharedBuffer,(char *)LastFile);
  1212.  
  1213.     if(Dummy = PathPart(SharedBuffer))
  1214.         *Dummy = 0;
  1215.  
  1216.     BlockWindow();
  1217.  
  1218.     if(AslRequestTags(RestoreRequest,
  1219.         ASL_File,    FilePart(LastFile),
  1220.         ASL_Dir,    SharedBuffer,
  1221.     TAG_DONE))
  1222.     {
  1223.         if(RestoreRequest -> fr_File[0])
  1224.         {
  1225.             strcpy((char *)SharedBuffer,(char *)RestoreRequest -> fr_Drawer);
  1226.  
  1227.             if(AddPart(SharedBuffer,RestoreRequest -> fr_File,256))
  1228.             {
  1229.                 strcpy((char *)LastFile,(char *)SharedBuffer);
  1230.  
  1231.                 UnblockWindow();
  1232.  
  1233.                 return(LastFile);
  1234.             }
  1235.         }
  1236.     }
  1237.  
  1238.     UnblockWindow();
  1239.  
  1240.     return(NULL);
  1241. }
  1242.  
  1243. VOID
  1244. ConPutC(UBYTE c)
  1245. {
  1246.     ConWriteRequest -> io_Command    = CMD_WRITE;
  1247.     ConWriteRequest -> io_Data    = &c;
  1248.     ConWriteRequest -> io_Length    = 1;
  1249.  
  1250.     DoIO((struct IORequest *)ConWriteRequest);
  1251. }
  1252.  
  1253. UBYTE
  1254. ConGetC()
  1255. {
  1256.     ULONG Signals;
  1257.     UBYTE c = 0;
  1258.  
  1259.     if(String)
  1260.     {
  1261.         if(*String)
  1262.             return(*String++);
  1263.         else
  1264.             String = NULL;
  1265.     }
  1266.  
  1267.     ConReadRequest -> io_Command    = CMD_READ;
  1268.     ConReadRequest -> io_Data    = &c;
  1269.     ConReadRequest -> io_Length    = 1;
  1270.  
  1271.     SendIO((struct IORequest *)ConReadRequest);
  1272.  
  1273.     FOREVER
  1274.     {
  1275.         Signals = Wait(SIG_WINDOW | SIG_CONSOLE | SIG_WORKBENCH | SIG_DEBUG);
  1276.  
  1277.         if(Signals & SIG_DEBUG)
  1278.         {
  1279.             struct IntuiMessage *Message;
  1280.  
  1281.             while(Message = (struct IntuiMessage *)GetMsg(DebugWindow -> UserPort))
  1282.                 ReplyMsg((struct Message *)Message);
  1283.  
  1284.             CloseDebugWindow();
  1285.         }
  1286.  
  1287.         if(Signals & SIG_WORKBENCH)
  1288.         {
  1289.             struct AppMessage    *AppMessage;
  1290.             BYTE             GotName = FALSE;
  1291.             LONG             i;
  1292.  
  1293.             while(AppMessage = (struct AppMessage *)GetMsg(WorkbenchPort))
  1294.             {
  1295.                 if(!GotName)
  1296.                 {
  1297.                     for(i = 0 ; !GotName && i < AppMessage -> am_NumArgs ; i++)
  1298.                     {
  1299.                         if(AppMessage -> am_ArgList[i] . wa_Lock)
  1300.                         {
  1301.                             if(NameFromLock(AppMessage -> am_ArgList[i] . wa_Lock,SharedBuffer,256))
  1302.                             {
  1303.                                 if(AddPart(SharedBuffer,AppMessage -> am_ArgList[i] . wa_Name,256))
  1304.                                 {
  1305.                                     struct DiskObject *Icon;
  1306.  
  1307.                                     if(Icon = GetDiskObject(SharedBuffer))
  1308.                                     {
  1309.                                         if(Icon -> do_Type == WBPROJECT)
  1310.                                         {
  1311.                                             UBYTE *Result;
  1312.  
  1313.                                             if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"FILETYPE"))
  1314.                                             {
  1315.                                                 if(!stricmp((char *)Result,"Z3SAVEFILE"))
  1316.                                                     GotName = TRUE;
  1317.                                             }
  1318.                                         }
  1319.  
  1320.                                         FreeDiskObject(Icon);
  1321.                                     }
  1322.                                 }
  1323.                             }
  1324.                         }
  1325.                     }
  1326.                 }
  1327.  
  1328.                 ReplyMsg((struct Message *)AppMessage);
  1329.             }
  1330.  
  1331.             if(GotName)
  1332.             {
  1333.                 AbortIO((struct IORequest *)ConReadRequest);
  1334.  
  1335.                 WaitIO((struct IORequest *)ConReadRequest);
  1336.  
  1337.                 SetSignal(0,SIG_CONSOLE);
  1338.  
  1339.                 String = "restore\r";
  1340.  
  1341.                 strcpy((char *)LastFile,(char *)SharedBuffer);
  1342.  
  1343.                 DontAsk = TRUE;
  1344.  
  1345.                 return(24);
  1346.             }
  1347.         }
  1348.  
  1349.         if(Signals & SIG_CONSOLE)
  1350.         {
  1351.             WaitIO((struct IORequest *)ConReadRequest);
  1352.  
  1353.             return(c);
  1354.         }
  1355.  
  1356.         if(Signals & SIG_WINDOW)
  1357.         {
  1358.             struct IntuiMessage    *IMsg;
  1359.             ULONG             Class,
  1360.                          Code;
  1361.  
  1362.             while(IMsg = GT_GetIMsg(Window -> UserPort))
  1363.             {
  1364.                 Class    = IMsg -> Class;
  1365.                 Code    = IMsg -> Code;
  1366.  
  1367.                 GT_ReplyIMsg(IMsg);
  1368.  
  1369.                 if(Class == IDCMP_CLOSEWINDOW)
  1370.                 {
  1371.                     if(!String)
  1372.                         String = MenuCodes[MEN_QUIT];
  1373.                 }
  1374.  
  1375.                 if(Class == IDCMP_MENUPICK)
  1376.                 {
  1377.                     struct MenuItem *Item,*ScriptIt = NULL;
  1378.  
  1379.                     while(Code != MENUNULL)
  1380.                     {
  1381.                         if(Item = ItemAddress(MachineMenu,Code))
  1382.                         {
  1383.                             LONG Menu = (LONG)GTMENUITEM_USERDATA(Item);
  1384.  
  1385.                             switch(Menu)
  1386.                             {
  1387.                                 case MEN_ABOUT:    ShowRequest("Zorkmachine 2.24\n\n\
  1388.  Created by\n\
  1389.   Matthias Pfaller\n\n\
  1390.  Amiga version %ld.%ld created by\n\
  1391.   Olaf Barthel\n\
  1392.    based on a fragmentary port by\n\
  1393.     martin@deepth.ulm.sub.org","Continue",VERSION,REVISION);
  1394.                                         break;
  1395.  
  1396.                                 case MEN_SPEECH:if(Item -> Flags & CHECKED)
  1397.                                             NarrateStory = TRUE;
  1398.                                         else
  1399.                                             NarrateStory = FALSE;
  1400.  
  1401.                                         if(!NarrateStory && SpeechProcess)
  1402.                                             Signal((struct Task *)SpeechProcess,SIG_STOP);
  1403.  
  1404.                                         AdjustTitle(NULL);
  1405.  
  1406.                                         break;
  1407.  
  1408.                                 default:    if(!String)
  1409.                                         {
  1410.                                             switch(Menu)
  1411.                                             {
  1412.                                                 case MEN_PALETTE:
  1413.  
  1414.                                                     EditPalette();
  1415.                                                     break;
  1416.  
  1417.                                                 case MEN_DEBUG:
  1418.  
  1419.                                                     DebugItem = Item;
  1420.  
  1421.                                                     if(Item -> Flags & CHECKED)
  1422.                                                     {
  1423.                                                         if(!OpenDebug())
  1424.                                                             Item -> Flags &= ~CHECKED;
  1425.                                                     }
  1426.                                                     else
  1427.                                                         CloseDebugWindow();
  1428.  
  1429.                                                     break;
  1430.  
  1431.                                                 case MEN_SCRIPT:
  1432.  
  1433.                                                     if(Item -> Flags & CHECKED)
  1434.                                                     {
  1435.                                                         ScriptIt = Item;
  1436.  
  1437.                                                         String = "script\r";
  1438.                                                     }
  1439.                                                     else
  1440.                                                         String = "unscript\r";
  1441.  
  1442.                                                     break;
  1443.  
  1444.                                                 case MEN_SAVE:
  1445.  
  1446.                                                     DontAsk = TRUE;
  1447.  
  1448.                                                     String = MenuCodes[Menu];
  1449.  
  1450.                                                     break;
  1451.  
  1452.                                                 case 0:
  1453.  
  1454.                                                     break;
  1455.  
  1456.                                                 default:
  1457.  
  1458.                                                     String = MenuCodes[Menu];
  1459.  
  1460.                                                     break;
  1461.                                             }
  1462.                                         }
  1463.  
  1464.                                         break;
  1465.                             }
  1466.  
  1467.                             Code = Item -> NextSelect;
  1468.                         }
  1469.                     }
  1470.  
  1471.                     if(ScriptIt)
  1472.                     {
  1473.                         BlockWindow();
  1474.  
  1475.                         if(GetProtocolName((UBYTE *)print_name))
  1476.                         {
  1477.                             ScriptIt -> Flags &= ~CHECKED;
  1478.  
  1479.                             String = "";
  1480.                         }
  1481.  
  1482.                         UnblockWindow();
  1483.                     }
  1484.                 }
  1485.             }
  1486.  
  1487.             if(String)
  1488.             {
  1489.                 AbortIO((struct IORequest *)ConReadRequest);
  1490.  
  1491.                 WaitIO((struct IORequest *)ConReadRequest);
  1492.  
  1493.                 SetSignal(0,SIG_CONSOLE);
  1494.  
  1495.                 return(24);
  1496.             }
  1497.         }
  1498.     }
  1499. }
  1500.  
  1501. VOID
  1502. ConPutS(UBYTE *s)
  1503. {
  1504.     ConWriteRequest -> io_Command    = CMD_WRITE;
  1505.     ConWriteRequest -> io_Data    = s;
  1506.     ConWriteRequest -> io_Length    = -1;
  1507.  
  1508.     DoIO((struct IORequest *)ConWriteRequest);
  1509. }
  1510.  
  1511. VOID
  1512. ConPrintf(UBYTE *Text,...)
  1513. {
  1514.     va_list VarArgs;
  1515.  
  1516.     va_start(VarArgs,Text);
  1517.     vsprintf(SharedBuffer,Text,VarArgs);
  1518.     va_end(VarArgs);
  1519.  
  1520.     ConPutS(SharedBuffer);
  1521. }
  1522.  
  1523. VOID
  1524. ConPutS2(UBYTE *a,UBYTE *b)
  1525. {
  1526.     ConWriteRequest -> io_Command    = CMD_WRITE;
  1527.     ConWriteRequest -> io_Data    = a;
  1528.     ConWriteRequest -> io_Length    = b - a;
  1529.  
  1530.     DoIO((struct IORequest *)ConWriteRequest);
  1531. }
  1532.  
  1533. VOID
  1534. ConCleanup()
  1535. {
  1536.     ThisProcess -> pr_WindowPtr = OldPtr;
  1537.  
  1538.     if(ConReadRequest)
  1539.     {
  1540.         if(ConReadRequest -> io_Device)
  1541.             CloseDevice((struct IORequest *)ConReadRequest);
  1542.  
  1543.         DeleteIORequest((struct IORequest *)ConReadRequest);
  1544.     }
  1545.  
  1546.     if(ConWriteRequest)
  1547.         DeleteIORequest((struct IORequest *)ConWriteRequest);
  1548.  
  1549.     if(ConReadPort)
  1550.         DeleteMsgPort(ConReadPort);
  1551.  
  1552.     if(ConWritePort)
  1553.         DeleteMsgPort(ConWritePort);
  1554.  
  1555.     if(WorkbenchWindow)
  1556.         RemoveAppWindow(WorkbenchWindow);
  1557.  
  1558.     if(WorkbenchPort)
  1559.     {
  1560.         struct Message *Message;
  1561.  
  1562.         while(Message = GetMsg(WorkbenchPort))
  1563.             ReplyMsg(Message);
  1564.  
  1565.         DeleteMsgPort(WorkbenchPort);
  1566.     }
  1567.  
  1568.     if(Window)
  1569.     {
  1570.         Window -> Flags |= WFLG_RMBTRAP;
  1571.  
  1572.         ClearMenuStrip(Window);
  1573.  
  1574.         CloseWindow(Window);
  1575.     }
  1576.  
  1577.     CloseDebugWindow();
  1578.  
  1579.     if(Screen)
  1580.         CloseScreen(Screen);
  1581.  
  1582.     if(MachineMenu)
  1583.         FreeMenus(MachineMenu);
  1584.  
  1585.     if(ProtocolRequest)
  1586.         FreeAslRequest(ProtocolRequest);
  1587.  
  1588.     if(SaveRequest)
  1589.         FreeAslRequest(SaveRequest);
  1590.  
  1591.     if(RestoreRequest)
  1592.         FreeAslRequest(RestoreRequest);
  1593.  
  1594.     DeleteSpeech();
  1595.  
  1596.     if(IFFParseBase)
  1597.         CloseLibrary(IFFParseBase);
  1598.  
  1599.     if(IconBase)
  1600.         CloseLibrary(IconBase);
  1601.  
  1602.     if(WorkbenchBase)
  1603.         CloseLibrary(WorkbenchBase);
  1604.  
  1605.     if(AslBase)
  1606.         CloseLibrary(AslBase);
  1607.  
  1608.     if(IntuitionBase)
  1609.         CloseLibrary((struct Library *)IntuitionBase);
  1610.  
  1611.     if(GfxBase)
  1612.         CloseLibrary((struct Library *)GfxBase);
  1613.  
  1614.     if(GadToolsBase)
  1615.         CloseLibrary(GadToolsBase);
  1616.  
  1617.     SoundCleanup();
  1618. }
  1619.  
  1620. BYTE
  1621. OpenConsoleStuff()
  1622. {
  1623.     struct Screen *PubScreen;
  1624.  
  1625.     ThisProcess = (struct Process *)FindTask(NULL);
  1626.  
  1627.     OldPtr = ThisProcess -> pr_WindowPtr;
  1628.  
  1629.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)))
  1630.     {
  1631.         ConCleanup();
  1632.  
  1633.         return(FALSE);
  1634.     }
  1635.  
  1636.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)))
  1637.     {
  1638.         ConCleanup();
  1639.  
  1640.         return(FALSE);
  1641.     }
  1642.  
  1643.     if(!(GadToolsBase = OpenLibrary("gadtools.library",37)))
  1644.     {
  1645.         ConCleanup();
  1646.  
  1647.         return(FALSE);
  1648.     }
  1649.  
  1650.     if(!(AslBase = OpenLibrary("asl.library",37)))
  1651.     {
  1652.         ConCleanup();
  1653.  
  1654.         return(FALSE);
  1655.     }
  1656.  
  1657.     if(!IconBase)
  1658.         IconBase = OpenLibrary("icon.library",37);
  1659.  
  1660.     if(!IconBase)
  1661.     {
  1662.         ConCleanup();
  1663.  
  1664.         return(FALSE);
  1665.     }
  1666.  
  1667.     if(!(IFFParseBase = OpenLibrary("iffparse.library",37)))
  1668.     {
  1669.         ConCleanup();
  1670.  
  1671.         return(FALSE);
  1672.     }
  1673.  
  1674.     if(!(PubScreen = LockPubScreen(NULL)))
  1675.     {
  1676.         ConCleanup();
  1677.  
  1678.         return(FALSE);
  1679.     }
  1680.  
  1681.     sprintf(ScreenTitle,"Amiga %s (%s)",VERS,DATE);
  1682.  
  1683.     if(!ProgramName)
  1684.     {
  1685.         if(WBenchMsg)
  1686.         {
  1687.             if(WBenchMsg -> sm_NumArgs > 1)
  1688.                 ProgramName = FilePart(WBenchMsg -> sm_ArgList[1] . wa_Name);
  1689.             else
  1690.                 ProgramName = FilePart(WBenchMsg -> sm_ArgList[0] . wa_Name);
  1691.         }
  1692.         else
  1693.             ProgramName = "Zorkmachine";
  1694.     }
  1695.  
  1696.     if(CustomScreen)
  1697.     {
  1698.         struct Rectangle    Overscan;
  1699.         ULONG            DisplayID = GetVPModeID(&PubScreen -> ViewPort);
  1700.  
  1701.         if(QueryOverscan(DisplayID,&Overscan,OSCAN_TEXT))
  1702.         {
  1703.             LONG    Width = Overscan . MaxX - Overscan . MinX + 1,
  1704.                 NewWidth,
  1705.                 FontWidth = GfxBase -> DefaultFont -> tf_XSize;
  1706.  
  1707.             NewWidth = (Width / FontWidth) * FontWidth;
  1708.  
  1709.             Overscan . MinX += (Width - NewWidth) >> 1;
  1710.             Overscan . MaxX -= (Width - NewWidth) >> 1;
  1711.  
  1712.             Screen = OpenScreenTags(NULL,
  1713.                 SA_Title,    ScreenTitle,
  1714.                 SA_Depth,    1,
  1715.                 SA_ShowTitle,    TRUE,
  1716.                 SA_Behind,    TRUE,
  1717.                 SA_DisplayID,    DisplayID,
  1718.                 SA_DClip,    &Overscan,
  1719.                 SA_AutoScroll,    TRUE,
  1720.                 SA_SysFont,    0,
  1721.             TAG_DONE);
  1722.         }
  1723.         else
  1724.         {
  1725.             Screen = OpenScreenTags(NULL,
  1726.                 SA_Title,    ScreenTitle,
  1727.                 SA_Depth,    1,
  1728.                 SA_ShowTitle,    TRUE,
  1729.                 SA_Behind,    TRUE,
  1730.                 SA_DisplayID,    DisplayID,
  1731.                 SA_Overscan,    OSCAN_TEXT,
  1732.                 SA_AutoScroll,    TRUE,
  1733.                 SA_SysFont,    0,
  1734.             TAG_DONE);
  1735.         }
  1736.     }
  1737.     else
  1738.         Screen = NULL;
  1739.  
  1740.     if(!Screen)
  1741.     {
  1742.         WorkbenchBase = OpenLibrary("workbench.library",37);
  1743.  
  1744.         if(Window = OpenWindowTags(NULL,
  1745.             WA_InnerWidth,        GfxBase -> DefaultFont -> tf_XSize * 80,
  1746.             WA_InnerHeight,        GfxBase -> DefaultFont -> tf_YSize * 25,
  1747.             WA_Left,        0,
  1748.             WA_Top,            PubScreen -> BarHeight + 1,
  1749.             WA_Title,        "Zorkmachine",
  1750.             WA_ScreenTitle,        ScreenTitle,
  1751.             WA_MaxWidth,        PubScreen -> Width,
  1752.             WA_MaxHeight,        PubScreen -> Height,
  1753.             WA_CloseGadget,        TRUE,
  1754.             WA_IDCMP,        IDCMP_CLOSEWINDOW | IDCMP_MENUPICK,
  1755.             WA_SimpleRefresh,    TRUE,
  1756.             WA_SizeGadget,        TRUE,
  1757.             WA_SizeBBottom,        TRUE,
  1758.             WA_DragBar,        TRUE,
  1759.             WA_DepthGadget,        TRUE,
  1760.             WA_RMBTrap,        TRUE,
  1761.             WA_Activate,        TRUE,
  1762.             WA_AutoAdjust,        TRUE,
  1763.             WA_CustomScreen,    PubScreen,
  1764.         TAG_DONE))
  1765.         {
  1766.             WindowLimits(Window,Window -> BorderLeft + Window -> BorderRight + GfxBase -> DefaultFont -> tf_XSize * 20,PubScreen -> WBorTop + PubScreen -> Font -> ta_YSize + 1 + Window -> BorderBottom + 4 * GfxBase -> DefaultFont -> tf_YSize,0,0);
  1767.  
  1768.             SetFont(Window -> RPort,GfxBase -> DefaultFont);
  1769.  
  1770.             AdjustTitle(ProgramName);
  1771.         }
  1772.     }
  1773.     else
  1774.     {
  1775.         Window = OpenWindowTags(NULL,
  1776.             WA_Width,        Screen -> Width,
  1777.             WA_Height,        Screen -> Height - (Screen -> BarHeight + 2),
  1778.             WA_Left,        0,
  1779.             WA_Top,            Screen -> BarHeight + 2,
  1780.             WA_IDCMP,        IDCMP_MENUPICK,
  1781.             WA_SimpleRefresh,    TRUE,
  1782.             WA_RMBTrap,        TRUE,
  1783.             WA_Activate,        TRUE,
  1784.             WA_Borderless,        TRUE,
  1785.             WA_Backdrop,        TRUE,
  1786.             WA_CustomScreen,    Screen,
  1787.         TAG_DONE);
  1788.  
  1789.         if(TwoColours[0] || TwoColours[1])
  1790.             LoadRGB4(&Screen -> ViewPort,TwoColours,2);
  1791.     }
  1792.  
  1793.     UnlockPubScreen(NULL,PubScreen);
  1794.  
  1795.     if(!Window)
  1796.     {
  1797.         ConCleanup();
  1798.  
  1799.         return(FALSE);
  1800.     }
  1801.  
  1802.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  1803.  
  1804.     if(!(SaveRequest = AllocAslRequestTags(ASL_FileRequest,
  1805.         ASL_LeftEdge,    Window -> Width >> 2,
  1806.         ASL_TopEdge,    Window -> Height >> 2,
  1807.         ASL_Width,    Window -> Width >> 1,
  1808.         ASL_Height,    Window -> Height >> 1,
  1809.         ASL_Window,    Window,
  1810.         ASL_Hail,    "Save as...",
  1811.         ASL_OKText,    "Save",
  1812.         ASL_File,    "Story.Save",
  1813.         ASL_FuncFlags,    FILF_SAVE | FILF_NEWIDCMP,
  1814.     TAG_DONE)))
  1815.     {
  1816.         ConCleanup();
  1817.  
  1818.         return(FALSE);
  1819.     }
  1820.  
  1821.     if(!(RestoreRequest = AllocAslRequestTags(ASL_FileRequest,
  1822.         ASL_LeftEdge,    Window -> Width >> 2,
  1823.         ASL_TopEdge,    Window -> Height >> 2,
  1824.         ASL_Width,    Window -> Width >> 1,
  1825.         ASL_Height,    Window -> Height >> 1,
  1826.         ASL_Window,    Window,
  1827.         ASL_Hail,    "Restore...",
  1828.         ASL_OKText,    "Restore",
  1829.         ASL_File,    "Story.Save",
  1830.         ASL_FuncFlags,    FILF_NEWIDCMP,
  1831.     TAG_DONE)))
  1832.     {
  1833.         ConCleanup();
  1834.  
  1835.         return(FALSE);
  1836.     }
  1837.  
  1838.     if(!GetCurrentDirName(SharedBuffer,256))
  1839.         SharedBuffer[0] = 0;
  1840.  
  1841.     if(!(ProtocolRequest = AllocAslRequestTags(ASL_FileRequest,
  1842.         ASL_LeftEdge,    Window -> Width >> 2,
  1843.         ASL_TopEdge,    Window -> Height >> 2,
  1844.         ASL_Width,    Window -> Width >> 1,
  1845.         ASL_Height,    Window -> Height >> 1,
  1846.         ASL_Window,    Window,
  1847.         ASL_Hail,    "Select protocol file",
  1848.         ASL_OKText,    "Select",
  1849.         ASL_File,    "Story.Protocol",
  1850.         ASL_Dir,    SharedBuffer,
  1851.         ASL_FuncFlags,    FILF_SAVE | FILF_NEWIDCMP,
  1852.     TAG_DONE)))
  1853.     {
  1854.         ConCleanup();
  1855.  
  1856.         return(FALSE);
  1857.     }
  1858.  
  1859.     if(WorkbenchBase)
  1860.     {
  1861.         if(WorkbenchPort = CreateMsgPort())
  1862.             WorkbenchWindow = AddAppWindow(0,0,Window,WorkbenchPort,NULL);
  1863.     }
  1864.  
  1865.     if(!(VisualInfo = GetVisualInfo(Window -> WScreen,TAG_DONE)))
  1866.     {
  1867.         ConCleanup();
  1868.  
  1869.         return(FALSE);
  1870.     }
  1871.  
  1872.     if(!(MachineMenu = CreateMenus(MachineMenuConfig,
  1873.         GTMN_FrontPen,    0,
  1874.     TAG_DONE)))
  1875.     {
  1876.         ConCleanup();
  1877.  
  1878.         return(FALSE);
  1879.     }
  1880.  
  1881.     if(!(LayoutMenus(MachineMenu,VisualInfo,
  1882.         GTMN_TextAttr,    Window -> WScreen -> Font,
  1883.     TAG_DONE)))
  1884.     {
  1885.         ConCleanup();
  1886.  
  1887.         return(FALSE);
  1888.     }
  1889.  
  1890.     if(!(ConReadPort = CreateMsgPort()))
  1891.     {
  1892.         ConCleanup();
  1893.  
  1894.         return(FALSE);
  1895.     }
  1896.  
  1897.     if(!(ConWritePort = CreateMsgPort()))
  1898.     {
  1899.         ConCleanup();
  1900.  
  1901.         return(FALSE);
  1902.     }
  1903.  
  1904.     if(!(ConReadRequest = (struct IOStdReq *)CreateIORequest(ConReadPort,sizeof(struct IOStdReq))))
  1905.     {
  1906.         ConCleanup();
  1907.  
  1908.         return(FALSE);
  1909.     }
  1910.  
  1911.     if(!(ConWriteRequest = (struct IOStdReq *)CreateIORequest(ConWritePort,sizeof(struct IOStdReq))))
  1912.     {
  1913.         ConCleanup();
  1914.  
  1915.         return(FALSE);
  1916.     }
  1917.  
  1918.     ConReadRequest -> io_Data    = Window;
  1919.     ConReadRequest -> io_Length    = sizeof(struct Window);
  1920.  
  1921.     if(OpenDevice("console.device",CONU_SNIPMAP,(struct IORequest *)ConReadRequest,CONFLAG_DEFAULT))
  1922.     {
  1923.         ConCleanup();
  1924.  
  1925.         return(FALSE);
  1926.     }
  1927.  
  1928.     CopyMem(ConReadRequest,ConWriteRequest,sizeof(struct IOStdReq));
  1929.  
  1930.     ConWriteRequest -> io_Message . mn_ReplyPort = ConWritePort;
  1931.  
  1932.     SetMenuStrip(Window,MachineMenu);
  1933.  
  1934.     Forbid();
  1935.  
  1936.     strcpy(DefaultFontName,GfxBase -> DefaultFont -> tf_Message . mn_Node . ln_Name);
  1937.  
  1938.     DefaultFont . ta_Name    = DefaultFontName;
  1939.     DefaultFont . ta_YSize    = GfxBase -> DefaultFont -> tf_YSize;
  1940.     DefaultFont . ta_Style    = GfxBase -> DefaultFont -> tf_Style;
  1941.     DefaultFont . ta_Flags    = GfxBase -> DefaultFont -> tf_Flags & ~FPF_REMOVED;
  1942.  
  1943.     DefaultFontWidth = GfxBase -> DefaultFont -> tf_XSize;
  1944.  
  1945.     Permit();
  1946.  
  1947.     if(!CreateSpeech())
  1948.         OffMenu(Window,FULLMENUNUM(2,9,NOSUB));
  1949.  
  1950.     if(!Screen)
  1951.         OffMenu(Window,FULLMENUNUM(0,6,NOSUB));
  1952.  
  1953.     Window -> Flags &= ~WFLG_RMBTRAP;
  1954.  
  1955.         ScreenToFront(Window -> WScreen);
  1956.  
  1957.     return(TRUE);
  1958. }
  1959.